package com.ibox.core.book.utils;

import com.ibox.core.book.bean.TopRankList;

import io.reactivex.Flowable;
import okhttp3.OkHttpClient;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;

/**
 * Project IBox
 * Created by Amos
 * Created on 2017-10-12
 * Desc
 */

public class BookApi {
    public static BookApi instance;
    private BookApiService mApiService;

    public BookApi(OkHttpClient client) {
        Retrofit retrofit = new Retrofit.Builder()
                .baseUrl(BookConstant.BOOK_BASE_URL)
                .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
                .addConverterFactory(GsonConverterFactory.create())
                .client(client)
                .build();
        mApiService = retrofit.create(BookApiService.class);
    }

    /**
     * 获取BookApi实例
     *
     * @param client
     * @return
     */
    public static BookApi getInstance(OkHttpClient client) {
        if (instance == null) {
            instance = new BookApi(client);
        }
        return instance;
    }

    /**
     * 获取所有的排行榜
     *
     * @return
     */
    public Flowable<TopRankList> getTopRankList() {
        return mApiService.getTopRankList();
    }
}
